//**解决问题**//
//某些情况下,我们会过度使用继承来扩展对象的功能，例如功能的大量扩展可能带来子类的膨胀
//动态的给对象增加一些额外的职责，消除重复代码
class Stream
{
public:

	virtual char Read(int number) = 0;
	virtual void Seek(int position) = 0;
	virtual char Write(char data) = 0;

	~virtual Stream(){}
};

//主体类 文件流
class FileStream: public Stream
{
public:
	virtual char Read(int number)
	{

	}

	virtual void Seek(int position)
	{

	}

	virtual void Write(char data)
	{

	}
};

//主体类 网络流
class NetworkStream: public Stream
{
public:
	virtual char Read(int number)
	{

	}

	virtual void Seek(int position)
	{

	}

	virtual void Write(char data)
	{

	}
};
 
//主体类 内存流
class MemoryStream: public Stream
{
public:
	virtual char Read(int number)
	{

	}

	virtual void Seek(int position)
	{

	}

	virtual void Write(char data)
	{

	}
};

//额外的操作 Decorator
//装饰类很多，额外操作可以上提，创建基类
//在上面的三个主体类的基础上再做扩展，即装饰
class CryptoStream: public Stream
{
	Stream* stream;

public:
	CryptoStream(Stream* stm):stream(stm)
	{

	}

	virtual char Read(int number)
	{
		//额外的加密操作
		stream->Read(number); //读文件流
	}
	virtual char Seek(int position)
	{
		//额外的加密操作
		stream->Seek(position); //读文件流
	}
	virtual void Write(char data)
	{
		//额外的加密操作
		stream->Write(char data);//写文件流
	}
}

void Process()
{
	FileStream* s1 = new FileStream();
	CryptoStream* s2 = new CryptoStream(s1);
	BufferedStream* s3 = new BufferedStream(s1);
}
